package com.lijie.bs_recruit.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lijie.bs_recruit.mapper.JobcollectionMapper;
import com.lijie.bs_recruit.model.Jobcollection;
import com.lijie.bs_recruit.service.JobcollectionService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lijie
 * @since 2021-04-07
 */
@Service
public class JobcollectionServiceImpl extends ServiceImpl<JobcollectionMapper, Jobcollection> implements JobcollectionService {

    @Override
    public Boolean changeIsDeleted(Jobcollection jobcollection ,Integer deleted) {
        UpdateWrapper<Jobcollection> wrapper=new UpdateWrapper<>();
        wrapper.eq("userId", jobcollection.getUserId())
                .eq("positionId",jobcollection.getPositionId() )
                .set("isDeleted",deleted);
        int update = baseMapper.update(jobcollection, wrapper);
        return update>0? true:false;
    }

    @Override
    public Jobcollection getJobCollection(Jobcollection jobcollection,Integer deleted) {
        QueryWrapper<Jobcollection> wrapper=new QueryWrapper<>();
        wrapper.eq("userId", jobcollection.getUserId())
                .eq("positionId", jobcollection.getPositionId());
        if(deleted!=null){
            wrapper.eq("isDeleted", deleted);
        }
        Jobcollection one = baseMapper.selectOne(wrapper);
        return one;
    }

    @Override
    public PageInfo<Jobcollection> selJobCollectionByUserId(Integer pageIndex ,Jobcollection jobcollection) {
        List<Jobcollection> applicants = baseMapper.selJobCollectionByUserId(jobcollection.getUserId());
        PageHelper.startPage(pageIndex,5);
        PageInfo<Jobcollection> pageInfo = new PageInfo<>(applicants);
        return pageInfo;
    }


}
